<template>
  <div class="input">
    <div class="placeholder"
         :class="[content!=''||isFocused?'focused':'']"
         @click="onClickPlaceHolder">
      {{placeholder}}
    </div>
    <div class="textfield">
      <input ref="input"
             v-model="content"
             @input="update"
             @focusin="willFocusIn"
             @focusout="willLostFocus"
             type="text"/>
    </div>
  </div>
</template>

<script>
    export default {
      name: "normal_textfield",
      props:{
        placeholder:{
        	type: String,
          default: "",
        },

      },
      data(){
        return {
          isFocused: false,
          type: 'password',
          content: '',
        }
      },
      methods:{
        willFocusIn(){
          console.log('will focus in')
        },
        update(){
          console.log('update',this.content);
        },
        willLostFocus(){
          console.log('will lost focus');
          this.isFocused = false;
        },
        onClickPlaceHolder(){
          console.log('placeholder clicked');
          this.isFocused = true;
          this.$refs['input'].focus();
        },
        getText(){
          return this.content;
        },
        setText(content){
        	this.content = content;
        }
      }
    }
</script>

<style lang="less" scoped>
  @inputHeight: 30px;
  @textfieldHeight: 30px;
  .input{
    text-align: left;
    height:@inputHeight;
    width: 100%;
    padding-top: @inputHeight - @textfieldHeight + 20px;
  }

  .placeholder{
    margin-top: -@textfieldHeight;
    position: relative;
    top: @textfieldHeight;
    font-size: 20px;
    height: @textfieldHeight;
    transition: 0.5s ease;
  }

  .placeholder.focused{
    color: rgba(0,0,0,0.3);
    font-size: 15px;
    top:10px;
  }
  .textfield{
    height: @textfieldHeight;
  }
  .textfield input{
    background-color: rgba(0,0,0,0);
    width: 100%;
    border-style: none;
    border-bottom: solid 1px rgba(0,0,0,0.4);
    font-size: 20px;
  }
</style>
